/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ces31.ChineseDicesServer;

//import ChineseDicesCommon.ClientInterface;
import ces31.ChineseDicesCommon.ServidorInterface;
import java.rmi.registry.Registry;
/**
 *
 * @author Anderson Aiziro
 */
public class SO_Servidor{
 
    
    public static void main(String args[]){
        System.out.println("Iniciando Servidor...");
        getServerInstance().iniciarServidor();
    }

    private static String createPolicyPath(){
		StringBuffer policypath = new StringBuffer(System.getProperty("user.dir"));
		if(policypath.charAt(0) == 'C'){
            policypath.setCharAt(0,':');
            policypath.setCharAt(1,'\\');
			return "file" + policypath.toString();
		}
		return "file:/" + policypath.toString();
	}
    
    public void iniciarServidor(){
     
        System.out.println("Iniciando servico...");
         try {
             /*COMECO DO PATH --> file:\\Users\\Anderson Aiziro\\Documents\\NetBeansProjects\\chineseDices*/
           // System.setProperty("java.security.policy",createPolicyPath() + File.separator + "server.policy");
         //   System.out.println(System.getProperty("java.security.policy"));

            //System.setProperty("java.rmi.server.codebase", /*getPath()+*/  "file:\\Users\\Anderson Aiziro\\Documents\\NetBeansProjects\\chineseDices\\build\\classes");

          //  System.setSecurityManager(new RMISecurityManager());
            Registry registry = java.rmi.registry.LocateRegistry.createRegistry(ServidorInterface.port);
            registry.rebind(ServidorInterface.bindname, new SO_Servidor_Facade());
            System.out.println(ServidorInterface.port);
        } catch (Exception e) {
            System.out.println("Nao foi possivel iniciar o servidor " + e.toString());
        }
    }

    public void encerrarServidor(){
        System.exit(0);
    }

    public static SO_Servidor getServerInstance() {
        return serverinstance;
    }

    private static SO_Servidor serverinstance = new SO_Servidor();

}
